package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.CarTypeAndCarLength;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.transport.GoodsSourceFilterEntity;
import com.sgb.kjwl.model.entity.transport.WeightAndVolumeEntity;
import com.sgb.kjwl.utils.VehicleConstant;
import com.sgb.kjwl.view.ui.adapter.map.AdapterOnItemClick;
import com.sgb.kjwl.view.ui.adapter.map.BasePopWindow;
import com.sgb.kjwl.view.ui.adapter.map.PopViewHolder;
import com.sgb.kjwl.view.ui.adapter.transport.CarLengthTransportAdapter4;
import com.sgb.kjwl.view.ui.adapter.transport.CarTypeTransportAdapter4;
import com.sgb.kjwl.view.ui.adapter.transport.WeightAndVolumeMinAndMaxAdapter1;
import com.swgk.core.customview.MaxRecyclerView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

/**
 * Describe:车型、车长单选器
 * Author:  yangLei
 * Date:    2021/8/16
 */
public class GoodsFilterPopWindow extends BasePopWindow implements View.OnClickListener {
    private static final String TAG = "GoodsMoreFilterPopWindow";
    private static final float WEIGHT_MIN_VALUE = 0f;
    private static final float WEIGHT_MAX_VALUE = 999.9f;
    private static final float VOLUME_MIN_VALUE = 0f;
    private static final float VOLUME_MAX_VALUE = 999.9f;
    public static final String DEFAULT_GOODS_TYPE = "Default_GoodsType";
    private GoodsSourceFilterEntity goodsSourceFilterEntity;
    private MaxRecyclerView carTypeList;
    private MaxRecyclerView carLengthList;
    private LinearLayout choose_weight_volume_layout;
    private TextView tv_reset;
    private TextView tv_sure;
    private TextView choosed_cartype;
    private TextView choosed_cartlen;
    private TextView choosedVolume;
    private TextView choosedWieght;
    private RecyclerView weightRecyclerView;
    private RecyclerView volumeRecyclerView;
    private WeightAndVolumeMinAndMaxAdapter1 weightAdapter;
    private WeightAndVolumeMinAndMaxAdapter1 volumeAdapter;
    private CarTypeTransportAdapter4 carTypeAdapter;
    private CarLengthTransportAdapter4 lengthAdapter;
    private ImageView iv_carLenght_more;
    private ImageView iv_carType_more;
    private String currentGoodsType = DEFAULT_GOODS_TYPE;
    private boolean showWightAndVolume = true;

    //车型车长关联数据
    private Map<String, List<GoodsInfoTypeEntity3>> carTypeNoAndCarLengthMap = new HashMap<>();
    //所有车型
    private List<GoodsInfoTypeEntity3> allCarsTypeList = new ArrayList<>();
    //有效的车型
    private List<GoodsInfoTypeEntity3> usefulCarsTypeList = new ArrayList<>();
    //对应车型可用的车长
    private List<GoodsInfoTypeEntity3> usefulCarsLengthList = new ArrayList<>();
    //当前选中的车型
    private List<GoodsInfoTypeEntity3> typeTempList = new ArrayList<>();
    //可见的车长数据集合
    private List<GoodsInfoTypeEntity3> lengthTempList = new ArrayList<>();
    //最后选中的车长数据
    private List<GoodsInfoTypeEntity3> lastCarLengthCheckedData = new ArrayList<>();
    //最后选中的车型数据
    private List<GoodsInfoTypeEntity3> lastCarTypeCheckedData = new ArrayList<>();

    public GoodsFilterPopWindow(Context context, boolean showWightAndVolume) {
        super(context, DIR_DOWN_UP);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN |
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        this.showWightAndVolume = showWightAndVolume;
    }

    public GoodsFilterPopWindow(Context context) {
        this(context, true);
    }

    @Override
    protected int popLayout() {
        return R.layout.app_pop_filter_goods_map;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        goodsSourceFilterEntity = new GoodsSourceFilterEntity();
        weightRecyclerView = holder.getPop().findViewById(R.id.weight_recyclerView);
        volumeRecyclerView = holder.getPop().findViewById(R.id.volume_recyclerView);
        choosedVolume = holder.getPop().findViewById(R.id.choosed_volume);
        choosedWieght = holder.getPop().findViewById(R.id.choosed_wieght);
        choosed_cartype = holder.getPop().findViewById(R.id.choosed_cartype);
        choosed_cartlen = holder.getPop().findViewById(R.id.choosed_cartlen);
        carTypeList = holder.getPop().findViewById(R.id.goods_car_type_list);
        carLengthList = holder.getPop().findViewById(R.id.goods_car_length_list);
        choose_weight_volume_layout = holder.getPop().findViewById(R.id.choose_weight_volume_layout);
        tv_reset = holder.getPop().findViewById(R.id.reset_step);
        tv_sure = holder.getPop().findViewById(R.id.sure_step);

        if (showWightAndVolume) {
            choose_weight_volume_layout.setVisibility(View.VISIBLE);
        } else {
            choose_weight_volume_layout.setVisibility(View.GONE);
        }

        tv_reset.setOnClickListener(this::onClick);
        tv_sure.setOnClickListener(this::onClick);
        initWeightRecyclerView();
        initVolumeRecyclerView();
        initCarTypeView(holder);
        initCarLengthView(holder);
    }

    /**
     * 将dip或dp值转换为px值，保证尺寸大小不变
     */
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    /**
     * 界面数据初始化
     *
     * @param tabGoodsType
     * @param carTypeAndCarLength
     */
    public void setCarTypeAndCarLength(String tabGoodsType, List<CarTypeAndCarLength> carTypeAndCarLength) {
        if (carTypeAndCarLength == null || tabGoodsType == null) {
            return;
        }
        //如果要展示的货物类型和上次的货物类型不相同，就重置记录的选中数据
        if (!currentGoodsTypeIsSameWithLast(tabGoodsType)) {
            this.currentGoodsType = tabGoodsType;
            clearCarTypeAndCarLengthChecked();
            resetVolume();
            resetWeight();
        }
        resetCarType();
        convertToUsefulCarsTypeList(carTypeAndCarLength);
        //显示车型
        resetCarType();
        setCarTypeShowState(true);

        //显示车长
        boolean lastSelectedCarType = lastCarTypeCheckedData != null && lastCarTypeCheckedData.size() != 0;
        if (lastSelectedCarType) {
            refreshCarLengthByCarType(lastCarTypeCheckedData);
        } else {
            refreshCarLengthByCarType(usefulCarsTypeList);
        }
    }

    private void clearCarTypeAndCarLengthChecked() {
        lastCarTypeCheckedData.clear();
        lastCarLengthCheckedData.clear();
    }

    private void convertToUsefulCarsTypeList(List<CarTypeAndCarLength> carTypeAndCarLength) {
        allCarsTypeList.clear();
        carTypeNoAndCarLengthMap.clear();
        for (CarTypeAndCarLength item : carTypeAndCarLength) {
            allCarsTypeList.add(new GoodsInfoTypeEntity3(item.getNo(), item.getName()));
            carTypeNoAndCarLengthMap.put(item.getNo(), item.getCarLenList());
        }
    }

    private void addCarLengthDefaultItem() {
        if (usefulCarsLengthList == null ||
                (usefulCarsLengthList.size() >= 1 && usefulCarsLengthList.get(0).getName().equals("不限"))) {
            return;
        }
        GoodsInfoTypeEntity3 entity3 = new GoodsInfoTypeEntity3();
        entity3.setNo(DEFAULT_GOODS_TYPE);
        entity3.setName("不限");
        usefulCarsLengthList.add(0, entity3);
    }

    private void addCarTypeDefaultItem() {
        if (usefulCarsTypeList == null ||
                (usefulCarsTypeList.size() >= 1 && usefulCarsTypeList.get(0).getName().equals("不限"))) {
            return;
        }
        GoodsInfoTypeEntity3 entity3 = new GoodsInfoTypeEntity3();
        entity3.setNo(DEFAULT_GOODS_TYPE);
        entity3.setName("不限");
        usefulCarsTypeList.add(0, entity3);
    }

    private void foldCarTypeData(boolean isFold) {
        if (null == usefulCarsTypeList) {
            return;
        }
        if (isFold) {
            if (usefulCarsTypeList.size() > 12) {
                typeTempList = usefulCarsTypeList.subList(0, 12);
                iv_carType_more.setImageResource(R.drawable.common_shouqi);
            } else {
                typeTempList = usefulCarsTypeList;
                iv_carType_more.setImageResource(R.drawable.common_zhankai);
            }
        } else {
            typeTempList = usefulCarsTypeList;
            iv_carType_more.setImageResource(R.drawable.common_zhankai);
        }
    }

    private void setCarTypeShowState(boolean isFoldCarType) {
        if (null != usefulCarsTypeList) {
            foldCarTypeData(isFoldCarType);
            carTypeAdapter.setDatas(typeTempList);
            carTypeAdapter.resetCheckDatas();
            if (lastCarTypeCheckedData == null || lastCarTypeCheckedData.size() == 0) {
                carTypeAdapter.setDefItem(-1);
                choosed_cartype.setText("");
                return;
            }
            StringBuilder lastCarTypeCheckedStr = new StringBuilder();
            for (GoodsInfoTypeEntity3 item : lastCarTypeCheckedData) {
                if (typeTempList.contains(item)) {
                    carTypeAdapter.setCheckDefault(typeTempList.indexOf(item));
                }
                if (!TextUtils.isEmpty(item.getNo()) && !TextUtils.isEmpty(item.getNo())) {
                    lastCarTypeCheckedStr.append(item.getName());
                    lastCarTypeCheckedStr.append(",");
                }
            }
            if (lastCarTypeCheckedStr.length() > 1)
                choosed_cartype.setText(lastCarTypeCheckedStr.substring(0, lastCarTypeCheckedStr.length() - 1));
        } else {
            iv_carType_more.setImageResource(R.drawable.common_shouqi);
            choosed_cartype.setText("");
        }
    }

    private void foldCarLengthData(boolean isFold) {
        if (null == usefulCarsLengthList) {
            return;
        }
        if (isFold) {
            if (usefulCarsLengthList.size() > 12) {
                lengthTempList = usefulCarsLengthList.subList(0, 12);
                iv_carLenght_more.setImageResource(R.drawable.common_shouqi);
            } else {
                lengthTempList = usefulCarsLengthList;
                iv_carLenght_more.setImageResource(R.drawable.common_zhankai);
            }
        } else {
            lengthTempList = usefulCarsLengthList;
            iv_carLenght_more.setImageResource(R.drawable.common_zhankai);
        }
    }

    /**
     * 展示车长筛选框信息
     *
     * @param isFold 是否折叠展示
     */
    private void setCarLengthShowState(boolean isFold) {
        if (null != usefulCarsLengthList) {
            foldCarLengthData(isFold);
            lengthAdapter.setDatas(lengthTempList);
            refreshLastCheckedLength();
            lengthAdapter.resetCheckDatas();
            //当上次选中的车长，在变更车型后依然有效的需要保证继续选中
            if (lastCarLengthCheckedData == null || lastCarLengthCheckedData.size() == 0) {
                lengthAdapter.setDefItem(-1);
                choosed_cartlen.setText("");
                return;
            }
            StringBuilder lastCarLenCheckedStr = new StringBuilder();
            for (GoodsInfoTypeEntity3 item : lastCarLengthCheckedData) {
                if (lengthTempList.contains(item)) {
                    int index = lengthTempList.indexOf(item);
                    lengthAdapter.setDefItem(index);
                } else {
                    lengthAdapter.setDefItem(-1);
                }
                if (!TextUtils.isEmpty(item.getName()) && !TextUtils.isEmpty(item.getNo())) {
                    lastCarLenCheckedStr.append(item.getName());
                    lastCarLenCheckedStr.append(",");
                }
            }
            if (TextUtils.isEmpty(lastCarLenCheckedStr)) {
                return;
            }
            choosed_cartlen.setText(lastCarLenCheckedStr.substring(0, lastCarLenCheckedStr.length() - 1));
        } else {
            iv_carLenght_more.setImageResource(R.drawable.common_shouqi);
            lastCarLengthCheckedData.clear();
            choosed_cartlen.setText("");
        }
    }

    public void refreshCarLengthByCarType(List<GoodsInfoTypeEntity3> carTypes) {
        if (carTypes == null || carTypes.size() == 0) {
            lengthAdapter.setDatas(new ArrayList<>());
            return;
        }
        usefulCarsLengthList.clear();
        for (GoodsInfoTypeEntity3 item : carTypes) {
            List<GoodsInfoTypeEntity3> infoTypeEntity3s = carTypeNoAndCarLengthMap.get(item.getNo());
            if (infoTypeEntity3s == null || infoTypeEntity3s.size() == 0) {
                continue;
            }
            usefulCarsLengthList.addAll(infoTypeEntity3s);
        }
//        removeDuplicateCarLength();
        addCarLengthDefaultItem();
        usefulCarsLengthList = VehicleConstant.sortCarLength(usefulCarsLengthList);
        setCarLengthShowState(true);
    }

    /**
     * 获取选中的车长
     * 包括上种车型中被选中，在当前车型中仍然有效的车长
     */
    private void refreshLastCheckedLength() {
        List<GoodsInfoTypeEntity3> usefulCheckedLength = new ArrayList<>();
        if (lastCarLengthCheckedData.size() > 0) {
            for (GoodsInfoTypeEntity3 item : lastCarLengthCheckedData) {
                if (usefulCarsLengthList.contains(item)) {
                    usefulCheckedLength.add(item);
                }
            }
        }
        lastCarLengthCheckedData.clear();
        boolean isCheckedFirstItem = lengthAdapter.getCheckDatas().size() >= 1 &&
                lengthAdapter.getCheckDatas().get(0).getName().equals("不限");
        if (isCheckedFirstItem) {
            return;
        }

        lastCarLengthCheckedData.addAll(usefulCheckedLength);
        lastCarLengthCheckedData.addAll(lengthAdapter.getCheckDatas());
        lastCarLengthCheckedData = removeDuplicate(lastCarLengthCheckedData);
    }

    private void refreshLastCheckedCarType() {
        //获取上次选中的车型中在当前货物类型中仍然有效的车型
        List<GoodsInfoTypeEntity3> usefulCheckedCarTypes = new ArrayList<>();
        for (GoodsInfoTypeEntity3 item : lastCarTypeCheckedData) {
            if (usefulCarsTypeList.contains(item)) {
                usefulCheckedCarTypes.add(item);
            }
        }

        lastCarTypeCheckedData.clear();
        boolean isCheckedFirstItem = carTypeAdapter.getCheckDatas().size() >= 1 &&
                carTypeAdapter.getCheckDatas().get(0).getName().equals("不限");
        if (isCheckedFirstItem) {
            return;
        }

        lastCarTypeCheckedData.addAll(usefulCheckedCarTypes);
        lastCarTypeCheckedData.addAll(carTypeAdapter.getCheckDatas());
        lastCarTypeCheckedData = removeDuplicate(lastCarTypeCheckedData);
    }

    /**
     * 车长数据去重
     */
    private void removeDuplicateCarLength() {
        usefulCarsLengthList.removeAll(Collections.singleton(null));
        LinkedHashSet<GoodsInfoTypeEntity3> set = new LinkedHashSet<>();
        set.addAll(usefulCarsLengthList);
        usefulCarsLengthList = new ArrayList<>(set);
    }

    private List<GoodsInfoTypeEntity3> removeDuplicate(List<GoodsInfoTypeEntity3> list) {
        if (list == null || list.size() == 0) return new ArrayList<>();
        list.removeAll(Collections.singleton(null));
        LinkedHashSet<GoodsInfoTypeEntity3> set = new LinkedHashSet<>();
        set.addAll(list);
        return new ArrayList<>(set);
    }

    /**
     * 初始化车型选择相关控件
     *
     * @param holder
     */
    private void initCarTypeView(PopViewHolder holder) {
        carTypeAdapter = new CarTypeTransportAdapter4(mContext, null);
        carTypeList.setLayoutManager(new GridLayoutManager(mContext, 4));
        carTypeList.setAdapter(carTypeAdapter);
        carTypeAdapter.setItemSelect(true);
        carTypeAdapter.setMultiSelect(false);
        carTypeAdapter.setLimit(true);
        carTypeAdapter.setOnItemClick(new AdapterOnItemClick<GoodsInfoTypeEntity3>() {
            @Override
            public void onItemClick(GoodsInfoTypeEntity3 goodsInfoTypeEntity3s, int position) {
                showCheckedCarType();
                lastCarTypeCheckedData.clear();
                lastCarTypeCheckedData.add(goodsInfoTypeEntity3s);
                boolean isSelectDefault = goodsInfoTypeEntity3s.getName().equals("不限");
                //选中不限
                if (isSelectDefault) {
                    refreshCarLengthByCarType(allCarsTypeList);
                    return;
                }
                //选中的有效车型
                refreshCarLengthByCarType(lastCarTypeCheckedData);
            }
        });
        iv_carType_more = holder.getPop().findViewById(R.id.car_type_more);
        iv_carType_more.setOnClickListener(this::onClick);
    }

    /**
     * 车型选择显示处理
     */
    private void showCheckedCarType() {
        if (carTypeAdapter.getCheckDatas() != null && carTypeAdapter.getCheckDatas().size() != 0) {
            if (carTypeAdapter.getCheckDatas().get(0).getName().equals("不限")) {
                lastCarTypeCheckedData.clear();
                choosed_cartype.setText("");
            } else {
                StringBuilder carTypeCheckedStr = new StringBuilder();
                for (GoodsInfoTypeEntity3 item : carTypeAdapter.getCheckDatas()) {
                    carTypeCheckedStr.append(item.getName());
                    carTypeCheckedStr.append(",");
                }
                choosed_cartype.setText(carTypeCheckedStr.substring(0, carTypeCheckedStr.length() - 1));
            }
        }
    }

    /**
     * 初始化车长选择相关控件
     *
     * @param holder
     */
    private void initCarLengthView(PopViewHolder holder) {
        lengthAdapter = new CarLengthTransportAdapter4(mContext, null);
        carLengthList.setLayoutManager(new GridLayoutManager(mContext, 4));
        carLengthList.setAdapter(lengthAdapter);
        lengthAdapter.setItemSelect(true);
        lengthAdapter.setMultiSelect(false);
        lengthAdapter.setLimit(true);
        lengthAdapter.setDefItem(-1);
        lengthAdapter.setOnItemClick(new AdapterOnItemClick<GoodsInfoTypeEntity3>() {
            @Override
            public void onItemClick(GoodsInfoTypeEntity3 goodsInfoTypeEntity3, int position) {
                showCheckedCarLen();
                lastCarLengthCheckedData.clear();
                lastCarLengthCheckedData.add(goodsInfoTypeEntity3);
            }
        });
        iv_carLenght_more = holder.getPop().findViewById(R.id.car_lenght_more);
        iv_carLenght_more.setOnClickListener(this::onClick);
    }

    /**
     * 车长选择显示处理
     */
    private void showCheckedCarLen() {
        if (lengthAdapter.getCheckDatas() != null && lengthAdapter.getCheckDatas().size() != 0) {
            if (lengthAdapter.getCheckDatas().get(0).getName().equals("不限")) {
                lastCarLengthCheckedData.clear();
                choosed_cartlen.setText("");
            } else {
                StringBuilder carLenCheckedStr = new StringBuilder();
                for (GoodsInfoTypeEntity3 item : lengthAdapter.getCheckDatas()) {
                    carLenCheckedStr.append(item.getName());
                    carLenCheckedStr.append(",");
                }
                choosed_cartlen.setText(carLenCheckedStr.substring(0, carLenCheckedStr.length() - 1));
            }
        }
    }

    public void resetAllFilterData() {
        carTypeAdapter.resetCheckDatas();
        carTypeAdapter.setDefItem(-1);
        lengthAdapter.resetCheckDatas();
        lengthAdapter.setDefItem(-1);
        lastCarLengthCheckedData.clear();
        lastCarTypeCheckedData.clear();
        resetCarTypeAndCarLength();
        resetVolume();
        resetWeight();

        goodsSourceFilterEntity.setLengthType(null);
        goodsSourceFilterEntity.setCarType(null);
    }

    private void resetCarTypeAndCarLength() {
        resetCarType();
        refreshCarLengthByCarType(usefulCarsTypeList);
        setCarTypeShowState(true);
    }

    private void resetCarType() {
        resetCarType(true);
    }

    private void resetCarType(boolean isAddDefaultItem) {
        usefulCarsTypeList = allCarsTypeList;
        if (isAddDefaultItem) {
            addCarTypeDefaultItem();
        }
    }

    private void initVolumeRecyclerView() {
        List<WeightAndVolumeEntity> datas = new ArrayList<>();
        datas.add(new WeightAndVolumeEntity(0, 10));
        datas.add(new WeightAndVolumeEntity(10, 20));
        datas.add(new WeightAndVolumeEntity(20, 30));
        datas.add(new WeightAndVolumeEntity(30, 40));
        datas.add(new WeightAndVolumeEntity(40, 50));
        datas.add(new WeightAndVolumeEntity(50, VOLUME_MAX_VALUE));
        volumeAdapter = new WeightAndVolumeMinAndMaxAdapter1(mContext, datas);
        volumeAdapter.setMultiSelect(false);
        volumeAdapter.setItemSelect(true);
        volumeAdapter.setDefItem(-1);
        volumeAdapter.setOnItemClick(new AdapterOnItemClick<WeightAndVolumeEntity>() {
            @Override
            public void onItemClick(WeightAndVolumeEntity weightAndVolumeEntity, int position) {
                goodsSourceFilterEntity.setVolume(String.valueOf(weightAndVolumeEntity.getMin()));
                goodsSourceFilterEntity.setMaxVolume(String.valueOf(weightAndVolumeEntity.getMax()));
                choosedVolume.setText(weightAndVolumeEntity.toString());
            }
        });
        volumeRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        volumeRecyclerView.setAdapter(volumeAdapter);
    }

    private void initWeightRecyclerView() {
        List<WeightAndVolumeEntity> datas = new ArrayList<>();
        datas.add(new WeightAndVolumeEntity(0, 5));
        datas.add(new WeightAndVolumeEntity(5, 10));
        datas.add(new WeightAndVolumeEntity(10, 15));
        datas.add(new WeightAndVolumeEntity(15, 20));
        datas.add(new WeightAndVolumeEntity(20, WEIGHT_MAX_VALUE));
        weightAdapter = new WeightAndVolumeMinAndMaxAdapter1(mContext, datas);
        weightAdapter.setMultiSelect(false);
        weightAdapter.setItemSelect(true);
        weightAdapter.setOnItemClick(new AdapterOnItemClick<WeightAndVolumeEntity>() {
            @Override
            public void onItemClick(WeightAndVolumeEntity weightAndVolumeEntity, int position) {
                goodsSourceFilterEntity.setMinWeight(String.valueOf(weightAndVolumeEntity.getMin()));
                goodsSourceFilterEntity.setMaxWeight(String.valueOf(weightAndVolumeEntity.getMax()));
                choosedWieght.setText(weightAndVolumeEntity.toString());

            }
        });
        weightRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        weightRecyclerView.setAdapter(weightAdapter);
    }

    private void resetWeight() {
        choosedWieght.setText("");
        weightAdapter.resetCheckDatas();
        weightAdapter.setDefItem(-1);
        goodsSourceFilterEntity.setMaxWeight(null);
        goodsSourceFilterEntity.setMinWeight(null);
    }

    private void resetVolume() {
        choosedVolume.setText("");
        volumeAdapter.resetCheckDatas();
        volumeAdapter.setDefItem(-1);
        goodsSourceFilterEntity.setVolume(String.valueOf(VOLUME_MIN_VALUE));
        goodsSourceFilterEntity.setMaxVolume(String.valueOf(VOLUME_MAX_VALUE));
    }

    public void hideTypeAndLength() {
        getContentView().findViewById(R.id.layout_car_type).setVisibility(View.GONE);
        getContentView().findViewById(R.id.layout_car_length).setVisibility(View.GONE);
    }

    public boolean isChooseFirstDefaultItem(List<GoodsInfoTypeEntity3> list) {
        if (list != null && list.size() >= 1) {
            return list.get(0).getName().equals("不限");
        }
        return false;
    }

    private boolean currentGoodsTypeIsSameWithLast(String goodsType) {
        if (TextUtils.isEmpty(goodsType)) return false;
        return goodsType.equals(currentGoodsType);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_transparent_layout:
            case R.id.bg_pop_gray_layout:
                dismiss();
                break;

            case R.id.sure_step:
                //更新车型筛选参数
                if (!isChooseFirstDefaultItem(lastCarTypeCheckedData)) {
                    refreshLastCheckedCarType();
                    goodsSourceFilterEntity.setCarType(lastCarTypeCheckedData);
                } else {
                    lastCarTypeCheckedData.clear();
                    goodsSourceFilterEntity.setCarType(null);
                }
                //更新车长筛选参数
                if (!isChooseFirstDefaultItem(lastCarLengthCheckedData)) {
                    refreshLastCheckedLength();
                    goodsSourceFilterEntity.setLengthType(lastCarLengthCheckedData);
                } else {
                    lastCarLengthCheckedData.clear();
                    goodsSourceFilterEntity.setLengthType(null);
                }

                onResultCallBack.result(goodsSourceFilterEntity);
                dissMiss();
                break;

            case R.id.reset_step:
                resetAllFilterData();
                break;

            case R.id.car_lenght_more:
                if (null != lengthAdapter.getDatas() && lengthAdapter.getDatas().size() > 0) {
                    if (lengthAdapter.getDatas().size() < usefulCarsLengthList.size()) {
                        setCarLengthShowState(false);
                    } else {
                        setCarLengthShowState(true);
                    }
                }
                break;

            case R.id.car_type_more:
                if (null != carTypeAdapter.getDatas() && carTypeAdapter.getDatas().size() > 0) {
                    if (carTypeAdapter.getDatas().size() < usefulCarsTypeList.size()) {
                        setCarTypeShowState(false);
                    } else {
                        setCarTypeShowState(true);
                    }
                }
                break;
        }
    }
}